package com.weixin.servlet.backstage;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.weixin.util.ValidateUtil;

/**
 * 登陆Servlet
 * @author 唐鑫明
 *
 */
@WebServlet("/YanZhenMa")
public class YanZhenMaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("image/jpeg");
		String[] codes= {"龙飞凤舞","谦虚戒骄","欣欣向荣","天下无双","闻鸡起舞","海阔天空","满腹经纶","两小无猜","金玉良缘","八仙过海","皆大欢喜","情非得已","精卫填海"};
		String code = codes[new Random().nextInt(13)];
		request.getSession().setAttribute("code", code);
		BufferedImage image = ValidateUtil.getValiDateCode(code);
		ImageIO.write(image, "jpeg", response.getOutputStream());
	}

}
